package edu.ztr.controller;

import edu.ztr.pojo.Key;
import edu.ztr.pojo.Result;
import edu.ztr.service.LoginServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin
@RestController
public class LoginController {

    @Autowired
    private LoginServer loginServer;

    @PostMapping("/login")
    public Result login(@RequestBody Key key) {
        log.info("成员登录：{}", key);
        Key e = loginServer.login(key);
        return e != null ? Result.success() : Result.error("用户名或密码错误");
    }
    @GetMapping("/getCheck")
    public String getCheckword(){
        String s = loginServer.getCheck();
        return s;
    }
    // 注册
    @PostMapping("/register")
    public Result register(@RequestBody Key key) {
        log.info("成员注册：{}", key);
        String e = loginServer.register(key);
        return e.equals("OK") ? Result.success() : Result.error(e);
    }

}
